<?php
namespace Admin\Controller;
use Think\Controller;
	class LoginController extends Controller{
		public function login(){
			$this->display();
		}
		public function doLogin(){
			$username=$_POST['username'];
			$pwd=$_POST['password'];
			$where['username']=$username;
				$admin=D('Admin');
				$arr=$admin->field('id,username,password,salt')->where($where)->find();
				if($arr){
					if ($arr['password']==md5($pwd.$arr['salt'])){
						$_SESSION['username']=$arr['username'];
						$_SESSION['id']=$arr['id'];
						$_SESSION['is_login']=1;
						$this->redirect('Index/index');
					}else{
						$this->error('密码错误');
					}
				}else{
					$this->error('该用户不存在');
				}
		}
		//退出
		public function logout(){
			$_SESSION=array();
				if(isset($_COOKIE[session_name()])){
					setcookie(session_name(),'',time()-1,'/');
				}
			session_destroy();
			$this->redirect('Index/index');
		}
	}
?>
